<?php
// @formatter:off
/**
 * @file dynamic.conf.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-07 02:16:25 +0000 (Fri, 07 Jun 2013) $
 *
 * $Id: dynamic.conf.php 71 2013-06-07 02:16:25Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/includes/dynamic.conf.php $
 */
// @formatter:on

// @formatter:off
//
// Setting default values for globals.
// @{
/**
 * @var WCGroupsHolder
 */
$wcGroupsHolder			= WCGroupsHolder::Instance();
/**
 * @var WCTagsHolder
 */
$wcTagsHolder			= WCTagsHolder::Instance();
/**
 * @var WCDirectoriesHolder
 */
$wcDirectoriesHolder		= WCDirectoriesHolder::Instance();
/**
 * @var WCComicsHolder
 */
$wcComicsHolder                 = WCComicsHolder::Instance();
/**
 * @var WCUsersHolder
 */
$wcUsersHolder                  = WCUsersHolder::Instance();
/**
 * @var WCUserDataHolder
 */
$wcUserDataHolder               = WCUserDataHolder::Instance();
/**
 * @var WCUsersHolder
 */
$wcUsersHolder                  = WCUsersHolder::Instance();
/**
 * @var WCTag
 */
$wcTag				= false;
/**
 * @var WCRulesHolder
 */
$wcRulesHolder			= WCRulesHolder::Instance();
/**
 * @var string
 */
$wcAction			= false;
/**
 * @var string
 */
$wcSubAction			= false;
/**
 * @var string
 */
$wcForbiddenAction		= false;
/**
 * @var bool
 */
$wcActionForbidden		= false;
/**
 * @var bool
 */
$wcMobileActionForbidden	= false;
/**
 * @var WCGroup
 */
$wcGroup			= false;
$wcGroupForbidden		= false;
$wcUser				= false;
$wcSubUser			= false;
/**
 * @var WCProfile
 */
$wcProfile			= new WCProfile();
/**
 * @var WCSessions
 */
$wcSession			= WCSessions::Instance();
/**
 * @var WCPageCache
*/
$wcPageCache			= false;
/**
 * @var WCReadRate
 */
$wcReadRate			= false;
/**
 * @var WCDirectory
 */
$wcDirectory			= false;
/**
 * @var WCComic
 */
$wcComic			= false;
/**
 * @var WCCollectionsHolder
 */
$wcCollectionsHolder		= WCCollectionsHolder::Instance();
/**
 * @var WCCollection
*/
$wcCollection			= false;
/**
 * @var WCCron
 */
$wcCron				= !defined("__SHELL__") ? null : WCCron::Instance();
/**
 * @var WCCron
*/
$wcToolsManager			= !defined("__SHELL__") ? null : WCToolsManager::Instance();
/**
 * @var WCOptions
*/
$wcOptions			= !defined("__SHELL__") ? null : WCOptions::Instance();
/**
 * @var array
*/
$wcThemeAssigns			= array();
/**
 * @var WCSearch
*/
$wcSearch			= WCSearch::Instance();
/**
 * @var WCLog
*/
$wcLog				= false;
/**
 * @var WCRule
 */
$wcRule				= false;
/**
 * @var
 */
$wcRuleAction			= false;
// @}
// @formatter:on
foreach($wcCompressors as $key => $value) {
	$pattern = array();
	foreach($value["extensions"] as $ext) {
		$pattern[] = "\.{$ext}$";
	}
	$wcCompressors[$key]["pattern"] = "/(".implode("|", $pattern).")/";
}

//
// Loading current group from url arguments.
if(isset($_REQUEST["group"])) {
	$wcGroup = $wcGroupsHolder->groupById($_REQUEST["group"]);
}

//
// Loading current user and profile based on current session.
if($wcSession->isLogged()) {
	$wcUser = $wcSession->user();
	$wcProfile->load($wcUser);
} else {
	$wcProfile->load();
}

//
// Loading current action from url arguments and its permissions.
// @{
if(isset($_REQUEST["action"]) && $_REQUEST["action"]) {
	$wcAction = $_REQUEST["action"];
	if($wcAction == WC_ACTION_CANVAS && isset($_REQUEST["saction"]) && $_REQUEST["saction"]) {
		$wcSubAction = $_REQUEST["saction"];
	}
} else {
	//
	// If no acction is specified in url, a default one is set.
	if(defined("__INDEX__")) {
		$wcAction = $wcDefaults["action"];
	} elseif(defined("__MOBILE__")) {
		$wcAction = $wcDefaults["mobile-action"];
	} else {
		$wcAction = false;
	}
}
// @}

//
// Loading current comic from url arguments.
// @{
if(isset($_REQUEST["comic"]) && $wcGroup) {
	$wcComic = $wcComicsHolder->item($_REQUEST["comic"], $wcGroup);

	if($wcComic && $wcComic->ok()) {
		//
		// Setting current directory.
		$wcDirectory = $wcComic->directory();
	} else {
		$wcComic = false;
	}
}
// @}

//
// Loading current directory from url arguments.
// If crent comic is set, this step is ignored because current directory has to
// be the current comic's directory.
if(!$wcComic && isset($_REQUEST["directory"]) && $wcGroup) {
	$wcDirectory = $wcDirectoriesHolder->item($_REQUEST["directory"], $wcGroup);
}

//
// Loading current collection from url arguments.
if($wcComic && $wcComic->collection > 0 && $wcGroup) {
	$wcCollection = $wcCollectionsHolder->item($wcComic->collection, $wcGroup);
} elseif(isset($_REQUEST["collection"]) && $wcGroup) {
	$wcCollection = $wcCollectionsHolder->item($_REQUEST["collection"], $wcGroup);
}

//
// Loading current tag from url arguments.
if(isset($_REQUEST["tag"]) && $wcGroup) {
	$wcTag = $wcTagsHolder->item($_REQUEST["tag"], $wcGroup);
}

//
// Loading current rule from url arguments.
if(isset($_REQUEST["rule"]) && $wcGroup) {
	$wcRule = $wcRulesHolder->item($_REQUEST["rule"], $wcGroup);

	if($wcRule->ok()) {
		if(isset($_REQUEST["raction"])) {
			foreach($wcRule->actions() as $action) {
				if($_REQUEST["raction"] == $action->id()) {
					$wcRuleAction = $action;
					break;
				}
			}
		}
	}
}

//
// Loading sub user from url arguments.
if(isset($_REQUEST["user"]) && $wcGroup) {
	if(!$wcUser || $_REQUEST["user"] != $wcUser->id()) {
		$wcSubUser = $wcUsersHolder->item($_REQUEST["user"]);
	}
}

foreach($wcUserXData as $key => $value) {
	if(is_numeric($key)) {
		$wcUserXData["_names"][] = $value["name"];
	}
}

$wcPageCache = WCPageCache::Instance();
$wcReadRate = WCReadRate::Instance();

if(!defined("__SHELL__")) {
	require_once "{$wcPaths["includes-directory"]}/dynamic.conf.grants.php";
}
if(!defined("__SHELL__")) {
	require_once "{$wcPaths["includes-directory"]}/dynamic.conf.themes.php";
}
?>